<template>
  <div class="Devicelist">
    <el-row :gutter='24' class='form' id='formt' style='background:#fff; position: relative;'>
      <el-col :span='7'>
        <div class='grid-content'>
          <el-form  :model='formR' label-width='95px' @submit.native.prevent >
            <el-form-item label=' IMEI 号' class='img-name'>
              <el-input v-model='formR.imei'  placeholder="请输入IMEI号" style='width: 200px;' clearable></el-input>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <el-col :span='7'>
        <div class='grid-content'>
          <el-form  :model='formR' label-width='100px' @submit.native.prevent >
            <el-form-item label='设备类型' class='img-name'>
              <el-select v-model="formR.devname" clearable placeholder="请选择" style="width: 200px;">
                <el-option v-for="item in options" :key="item.key" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <!-- <el-col :span='7'>
        <div class='grid-content date-picker'>
          <el-form :model='formR' label-width='100px' @submit.native.prevent class="demo-form">
            <el-form-item label='删除时间' class='img-name' >
              <el-date-picker placeholder="请选择删除时间" style='margin-left:40px; width: 200px' v-model="formR.create_time" type="date">
              </el-date-picker>
            </el-form-item>
          </el-form>
        </div>
      </el-col> -->
      <el-col :span='8' class='btn-cx'>
        <div class='grid-content '>
          <el-form :model='formR' label-width='100px' @submit.native.prevent style="float: right">
            <el-button type='primary' @click="condition" class="search-btn">查询</el-button>
          </el-form>
        </div>
      </el-col>
    </el-row>
    <!-- 表单列表 -->
    <div class="device-manage">
      <el-table :data="listData" stripe :header-cell-style="getRowClass" v-loading="loading">
        <el-table-column prop="num" label="序号" width='80'></el-table-column>
        <el-table-column prop="imei" label="IMEI号" ></el-table-column>
        <el-table-column prop="dev_equip_id" label="位置编号"></el-table-column>
        <el-table-column prop="devname" label="设备类型">
          <template slot-scope="scope">
            <div style="display: inline;" v-if="scope.row.devname =='fireplug'">消防栓</div>
            <div style="display: inline;" v-if="scope.row.devname =='scm'">烟感设备</div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="phone" label="设备安装区域"></el-table-column> -->
        <!-- <el-table-column prop="pushClientId" label="设备安装场所名称" ></el-table-column> -->
        <el-table-column prop="address" label="详细地址"></el-table-column>
        <el-table-column prop="dev_equip_time" label="安装时间"></el-table-column>
        <el-table-column prop="create_time" label="删除时间"></el-table-column>
      </el-table>
      <page-list
        :size.sync="dev_pageSize"
        :total="totals"
        :current.sync="dev_currentPage"
        @change="getListData"
      ></page-list>
     
    </div>
  </div>
</template>

<script>
import Config from "@/config";
import PageList from "@/components/PageList";
import { mapGetters } from "vuex";

export default {
  name: "DeviceManage",
  components: {
    PageList
  },
  data() {
    return {
      options: [
        {
          value: "",
          label: "全部"
        },
        {
          value: "fireplug",
          label: "消防栓"
        },
        {
          value: "scm",
          label: "烟感设备"
        }
      ],
      inputType: "", // 下拉搜索
      ops: {
        bar: {
          background: "#DDDEE0"
        }
      },
      // 查询
      formR: {},
      // 列表分页
      totals: 0,
      dev_currentPage: 1,
      dev_pageSize: 15,
      inputs: 15,
      //列表
      listData: [],
      // loading
      loading: true,
    };
  },
  methods: {
    // 表头添加背景颜色
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background:#f6f6f6";
      } else {
        return "";
      }
    },
    // 获取列表
    getListData() {
      this.loading = true;
      let url = `${Config.DEVICE_MANAGE_URL}/device_modify_history/list?page=${this.dev_currentPage - 1}&size=${this.dev_pageSize}`;
      let params ={
        action_name: 'unbind',
        create_time: this.formR.create_time ? this.formR.create_time : undefined,
        imei: this.formR.imei ? this.formR.imei : undefined,
        devname: this.formR.devname ? this.formR.devname : undefined,
      }
      this.$http.get(url, params).then(res => {
        res.array.forEach((item, i) => {
          if (this.dev_currentPage === 1) {
            item.num = i + 1;
          } else {
            item.num = (this.dev_currentPage - 1) * this.dev_pageSize + i + 1;
          }
          
          item.dev_equip_id = JSON.parse(item.old_data).dev_equip_id
          item.address = JSON.parse(item.old_data).equip_site_address
          item.dev_equip_time = JSON.parse(item.old_data).dev_equip_time ? JSON.parse(item.old_data).dev_equip_time.replace('T', ' '): ''
          item.create_time = item.create_time ? item.create_time.replace('T', ' '): ''
          
        });
        this.totals = res.allcount;
        this.listData = res.array;
        this.loading = false;
      });
    },
    condition(){
      this.dev_currentPage  = 1;
      this.getListData();
    },
    // 删除限制数量
    delectlist(){
      let url = `${Config.DEVICE_MANAGE_URL}/device_modify_history/count_by_action_imei`;
      let param = {
        user_id: this.user.id,
        action_name:'unbind'
      };
      this.$http.get(url,param).then(res =>{
        if(res.count <= 20){
          this.getListData()
        }else{
          this.getListData()
          this.$message({
            message: `主运营公司管理员：子运营公司管理员（${this.user.loginName}）删除了超过20个设备，请尽快联系对方！`,
            type: "error"
          })
        }
      })
    },
  },
  mounted() {
    // this.getListData();
    this.delectlist()
  },
  computed: {
    ...mapGetters("user", {
      module: "dealedModule",
      user: "getUser",
      role: "getRole",
      district: "getDistrict"
    })
  }
};
</script>

<style lang='scss' >
@import "../../../../static/scss/common.scss";
.Devicelist {
  width: 100%;
  height: 100%;
   // 搜索
  .el-input.is-disabled .el-input__inner {
    color: #606266;
    border: 0;
    background-color: #fff;
  }
  .el-row {
    padding: 0;
    .el-col {
      padding: 0 !important;
    }
  }
  .el-form {
    height: 110px;
    display: flex;
    align-items: center;
  }
  .el-form-item.img-name {
    font-family: "微软雅黑";
    font-size: 12px !important;
    font-weight: bold;
    color: #444;
    position: relative;
  }
  .el-form-item__label {
    font-size: 12px !important;
    padding: 0;
    text-align: left;
    text-indent: 51px;
  }
  .img-name /deep/ .el-form-item__label:before {
    position: absolute;
    display: block;
    left: 24px;
    top: 17px;
    content: " ";
    width: 15px;
    height: 20px;
    background: url("/static/image/common/left.png") no-repeat;
  }
  .img-name /deep/ .el-form-item__label:after {
    position: absolute;
    display: block;
    left: 104px;
    top: 17px;
    content: " ";
    width: 20px;
    height: 20px;
    background: url("/static/image/common/right.png") no-repeat;
  }
  .date-picker /deep/ .el-input--prefix .el-input__prefix {
    right: -120px
  }
  .el-form-item.img-name {
    margin: 10px 0 10px 0;
    .el-form-item__label{
      text-align: center;
    }
  }
  .form .el-input__inner {
    height: 28px !important;
    line-height: 28px !important;
    border: 1px solid #e4e4e4;
    padding: 0 0 0 10px!important;
    .el-icon-time{
      line-height: 0;
    }
    .el-range-separator{
      line-height: 25px;
    }
  }
  .form.el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  //列表
  .device-manage {
    width: 100%;
    height: auto;
    background: $white;
    margin-top: 24px;
    .export {
      height: 24px;
      line-height: 24px;
      margin-right: 27px;
      text-align: right;
      padding-top: 12px;
    }
    // 查看
    .dialog-see.el-dialog__wrapper {
      .el-dialog {
        width: 420px;
        height: 366px;
        position: absolute;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
        margin: auto !important;
        .el-dialog__body {
          .el-form {
            .el-form-item {
              .el-form-item__label {
                line-height: 36px;
              }
              .el-form-item__content {
                line-height: 36px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              }
            }
            //更换设备
            .el-form-item.changesImei {
              .el-form-item__content {
                line-height: 32px;
                .el-input {
                  .el-input__inner {
                    height: 32px;
                    line-height: 32px;
                    width: 260px;
                    border-radius: 0;
                  }
                }
              }
            }
          }
        }
        .el-dialog__footer {
          padding: 30px 0;
          background: $white;
        }
      }
    }

  }
}
</style>
